
<template>
  <view class="login-container">
    <view class="header">
      <view class="hello">Hello!</view>
      <view>欢迎使用品胜供应链订货平台</view>
    </view>
    <view class="form-comtainer">
      <view class="title">账号登录</view>
      <view class="form-content">
        <view class="label">账号</view>
        <view class="input-container">
          <input v-model="form.phone_" placeholder="请输入账号或手机号" placeholder-class="input-placeholder" />
        </view>
        <view class="label">密码</view>
        <view class="input-container">
          <input v-model="form.password" placeholder="请输入密码" placeholder-class="input-placeholder" />
        </view>

        <button class="login-btn" @tap="submit">登录</button>
        <button class="login-btn-wx" open-type="getUserInfo" @tap="submit">微信一键登录</button>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import MD5 from 'blueimp-md5'
import { ref } from 'vue';

import Apis from "@/services/modules/login"
import { useMemberStore } from '@/stores';
import type { LoginResState } from '@/types/login';
import { onLoad } from '@dcloudio/uni-app';

const form = ref({
  phone_: "px00001",
  //phone_: "c17760345367",
  password: "a123456",
  password_: "",
  check_: true
})

onLoad(() => {
  uni.getSetting({
    success: (res) => {
      if (res.authSetting['scope.userInfo']) {
        wx.getUserInfo({
          success: function (res) {
            console.log(res.userInfo)
            //用户已经授权过
          }
        })
      }
    },
  })
})

const submit = () => {

  form.value.password_ = MD5(form.value.phone_ + MD5(form.value.password))

  Apis.mixedLoginApi(form.value).then(res => {

    const { setProfile } = useMemberStore()

    setProfile(res.data as LoginResState)

    uni.switchTab({ url: "/pages/index/index" })
  })
}

</script>

<style lang="scss">
.login-container {
  height: 100vh;
  position: relative;

  .header {
    background: $uni-color-warning;
    height: 40vh;
    display: flex;
    flex-direction: column;
    align-content: center;
    justify-content: center;
    color: #fff;
    font-size: 18px;
    font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
    padding-left: 32px;

    //background-image: linear-gradient(0deg, $uni-color-warning 25%, transparent 25%);
    // linear-gradient(-45deg, $uni-color-warning 25%, transparent 25%),
    // linear-gradient(45deg, transparent 75%, $uni-color-warning 75%),
    // linear-gradient(-45deg, transparent 75%, $uni-color-warning 75%);
    // background-size: 10px 10px;
    // background-position: 0 0, 5px 5px, 10px -5px, 15px 0;

    .hello {
      font-size: 46px;
      font-weight: 600;
    }
  }

  .form-comtainer {
    height: 60vh;
    width: 92%;
    position: relative;
    top: -13vh;
    left: 4%;
    border-radius: 22px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background-color: rgba($color: #fff, $alpha: 0.4);

    .title {
      font-size: 18px;
      font-weight: 600;
      line-height: 52px;
      text-align: center;
      font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
      background-color: #fff;
      width: 50%;
      border-radius: 22px 22px 0 0;
      position: relative;

      &::after {
        content: "";
        width: 22px;
        height: 22px;
        background-color: red;
        // border-radius: 50px;
        // border: 12px solid #fff;
        z-index: 9;
      }
    }

    .form-content {
      background-color: #fff;
      flex: 1;
      padding: 52px 22px;

      .label {
        font-size: 16px;
        padding-left: 22px;
        margin-bottom: 12px;
        color: $uni-color-title;
        font-weight: bold;
      }

      .input-container {
        background-color: #f3f8fc;
        height: 42px;
        border-radius: 20px;
        padding-left: 20px;
        display: flex;
        align-items: center;
        margin-bottom: 18px;

        .input-placeholder {
          font-size: 14px;
        }
      }
    }

    .login-btn {
      background-color: $uni-color-warning;
      color: #fff;
      margin-top: 90px;
    }

    .login-btn-wx {
      background-color: $uni-color-success;
      color: #fff;
      margin-top: 20px;
    }
  }
}
</style>
